import org.junit.*;
import java.util.*;
import play.test.*;
import models.*;
/**
 * 
 * @author Sameha
 *
 */
public class Samiha extends UnitTest {
	@Test
	public void promoteAnddemoteIdea() {
		Fixtures.deleteAll();

		IdeaDeveloper developer1 = new IdeaDeveloper("Samiha Osama", "Samiha",
				"samiha", "samiha.ismail@student.guc.edu.eg", "17-2-1991",
				"address1");
		developer1.save();
		IdeaDeveloper developer2 = new IdeaDeveloper("Amira Osama", "Amira",
				"amira", "amira@hotmail.com", "17-10-1994", "address2");
		developer2.save();
		IdeaDeveloper developer3 = new IdeaDeveloper("Salma Osama", "Salma",
				"salma", "salma@hotmail.com", "17-6-2000", "address3");
		developer3.save();
		IdeaDeveloper developer4 = new IdeaDeveloper("Omnia Osama", "Omnia",
				"omnia", "omnia@hotmail.com", "19-10-2003", "address4");
		developer4.save();

		/******************************************************************************/

		Organization org1 = new Organization();
		org1.save();

		OrganizationLead lead1 = OrganizationLead.create(developer1);
		lead1.save();

		org1.creator = lead1;
		org1.save();

		Idea idea = Idea.createIdeaOrg("testing1", "testingggg1", lead1.id,
				org1.id);
		idea.promoteIdea();
		idea.save();
		assertEquals("true", idea.promotedForExecution);

		/*********************************************************************/

		Entities ent1 = Entities.create(org1);

		Organizer organizer = Organizer.create(developer2);

		organizer.manages.add(ent1);

		Idea idea2 = Idea.createIdeaEntity("testing2", "testingggg2",
				organizer.id, ent1.id);

		idea2.promoteIdea();
		idea2.demoteIdea();
		idea2.save();
		assertEquals("false", idea.promotedForExecution);

	}

	@Test
	public void promoteOrCloseOrReOpenTopic() {
		Fixtures.deleteAll();

		IdeaDeveloper developer1 = new IdeaDeveloper("Samiha Osama", "Samiha",
				"samiha", "samiha.ismail@student.guc.edu.eg", "17-2-1991",
				"address1");
		developer1.save();
		IdeaDeveloper developer2 = new IdeaDeveloper("Amira Osama", "Amira",
				"amira", "amira@hotmail.com", "17-10-1994", "address2");
		developer2.save();
		IdeaDeveloper developer3 = new IdeaDeveloper("Salma Osama", "Salma",
				"salma", "salma@hotmail.com", "17-6-2000", "address3");
		developer3.save();
		IdeaDeveloper developer4 = new IdeaDeveloper("Omnia Osama", "Omnia",
				"omnia", "omnia@hotmail.com", "19-10-2003", "address4");
		developer4.save();
		/******************************************************************************/

		Organization org1 = new Organization();
		org1.save();

		OrganizationLead lead1 = OrganizationLead.create(developer1);
		lead1.save();

		org1.creator = lead1;
		org1.save();

		Topic topic1 = Topic.createTopicOrg("testTopic", "testing for topic",
				org1.id, lead1.id);
		Idea idea1 = Idea.createIdeaTopic("test topic1", "for promoting topic",
				lead1.id, topic1.id);
		idea1.promoteIdea();
		idea1.save();
		topic1.promoteTopic();
		topic1.save();
		assertEquals("true", topic1.promotedForExecution);

		/*********************************************************************/

		Topic topic2 = Topic.createTopicOrg("testTopic",
				"testing for close and reopen topic", org1.id, lead1.id);
		topic2.closeTopic();
		topic2.save();
		assertEquals("true", topic2.closed);
		topic2.reOpenTopic();
		topic2.save();
		assertEquals("false", topic2.closed);
		Idea idea2 = Idea.createIdeaTopic("test topic1",
				"for closing and reOpening topic", lead1.id, topic2.id);
		topic2.closeTopic();
		topic2.save();
		assertEquals("true", topic2.closed);
		topic2.reOpenTopic();
		topic2.save();
		assertEquals("false", topic2.closed);

	}

	@Test
	public void communityCounter() {
		Fixtures.deleteAll();

		IdeaDeveloper developer1 = new IdeaDeveloper("Samiha Osama", "Samiha",
				"samiha", "samiha.ismail@student.guc.edu.eg", "17-2-1991",
				"address1");
		developer1.save();
		IdeaDeveloper developer2 = new IdeaDeveloper("Amira Osama", "Amira",
				"amira", "amira@hotmail.com", "17-10-1994", "address2");
		developer2.save();
		IdeaDeveloper developer3 = new IdeaDeveloper("Salma Osama", "Salma",
				"salma", "salma@hotmail.com", "17-6-2000", "address3");
		developer3.save();
		IdeaDeveloper developer4 = new IdeaDeveloper("Omnia Osama", "Omnia",
				"omnia", "omnia@hotmail.com", "19-10-2003", "address4");
		developer4.save();
		/******************************************************************************/

		assertEquals(0, developer1.communityCounter);
		developer1.incrementCounter(10);
		developer1.save();
		assertEquals(10, developer1.communityCounter);

		developer2.decrementCounter(15);
		developer2.save();
		assertEquals(-15, developer2.communityCounter);

	}

}
